/*     */ package com.yc.dao.station;
/*     */ 
/*     */ import btsm.bean.dbConnector;
/*     */ import btsm.bean.sysPro;
/*     */ import com.yc.dao.model.DictionaryBO;
/*     */ import com.yc.dao.model.DistrictcodeBO;
/*     */ import com.yc.util.ListContentsBFO;
/*     */ import java.sql.ResultSet;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ 
/*     */ public class CommDAO
/*     */ {
/*  21 */   private static final Log log = LogFactory.getLog(CommDAO.class);
/*     */ 
/*  23 */   private dbConnector dbcon = null;
/*  24 */   public static Map dictMap = null;
/*     */ 
/*  26 */   private String strDQXSFilter = "5113%";
/*  27 */   private sysPro sPro = new sysPro();
/*     */ 
/*     */   public CommDAO() {
/*  30 */     this.strDQXSFilter = this.sPro.getPFilter();
/*  31 */     ResultSet rs = null;
/*     */     try
/*     */     {
/*  34 */       if (dictMap == null)
/*     */       {
/*  36 */         dictMap = new HashMap();
/*  37 */         dbConInit();
/*  38 */         String strSQL = "select * from dictionary order by dictype";
/*  39 */         log.info(strSQL);
/*  40 */         rs = this.dbcon.execQuery(strSQL);
/*  41 */         while (rs.next()) {
/*  42 */           DictionaryBO bo = new DictionaryBO();
/*  43 */           String strdictype = rs.getString("dictype");
/*  44 */           bo.setDicname(rs.getString("dicname"));
/*  45 */           bo.setDictype(strdictype);
/*  46 */           bo.setDiccode(rs.getString("diccode"));
/*  47 */           List list = null;
/*  48 */           if (dictMap.containsKey(strdictype))
/*     */           {
/*  50 */             list = (List)dictMap.get(strdictype);
/*     */           }
/*     */           else
/*  53 */             list = new ArrayList();
/*  54 */           list.add(bo);
/*  55 */           dictMap.put(strdictype, list);
/*     */         }
/*     */       }
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/*  61 */       e.printStackTrace();
/*  62 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/*  65 */       dbConClose();
/*     */     }
/*     */   }
/*     */ 
/*  69 */   private void dbConInit() { if (this.dbcon == null)
/*  70 */       this.dbcon = new dbConnector();
/*     */   }
/*     */ 
/*     */   private void dbConClose()
/*     */   {
/*  75 */     if (this.dbcon != null)
/*  76 */       this.dbcon.closeAll();
/*  77 */     this.dbcon = null;
/*     */   }
/*     */ 
/*     */   public List getDirctoryByType(String strType)
/*     */   {
/*  83 */     return (List)dictMap.get(strType);
/*     */   }
/*     */ 
/*     */   public List scdqxslist() throws Exception
/*     */   {
/*  88 */     List list = new ArrayList();
/*  89 */     ResultSet rs = null;
/*     */     try
/*     */     {
/*  92 */       dbConInit();
/*  93 */       String scsql = "select distcode,district from districtcode where distcode like \"" + this.strDQXSFilter + "\" order by distcode ";
/*     */ 
/*  95 */       log.info(scsql);
/*  96 */       rs = this.dbcon.execQuery(scsql);
/*  97 */       while (rs.next()) {
/*  98 */         DistrictcodeBO bo = new DistrictcodeBO();
/*  99 */         bo.setDistcode(rs.getString("distcode"));
/* 100 */         bo.setDistrict(rs.getString("district"));
/* 101 */         list.add(bo);
/*     */       }
/*     */     }
/*     */     catch (Exception e) {
/* 105 */       e.printStackTrace();
/* 106 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 109 */       dbConClose();
/*     */     }
/* 111 */     return list;
/*     */   }
/*     */ 
/*     */   public List qetDictTypeList() throws Exception
/*     */   {
/* 116 */     List list = new ArrayList();
/* 117 */     ResultSet rs = null;
/*     */     try
/*     */     {
/* 120 */       dbConInit();
/* 121 */       String scsql = "select distinct dictype,dictypename from dictionary  ";
/*     */ 
/* 123 */       log.info(scsql);
/* 124 */       rs = this.dbcon.execQuery(scsql);
/* 125 */       while (rs.next()) {
/* 126 */         DictionaryBO bo = new DictionaryBO();
/* 127 */         bo.setDictype(rs.getString("dictype"));
/* 128 */         bo.setDictypename(rs.getString("dictypename"));
/* 129 */         list.add(bo);
/*     */       }
/*     */     }
/*     */     catch (Exception e) {
/* 133 */       e.printStackTrace();
/* 134 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 137 */       dbConClose();
/*     */     }
/* 139 */     return list;
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getDicList(Map condition)
/*     */   {
/* 145 */     log.info(" query dictionary begin .");
/* 146 */     dbConInit();
/* 147 */     ListContentsBFO bfo = new ListContentsBFO();
/* 148 */     int start = Integer.parseInt(condition.get("start").toString());
/* 149 */     int limit = Integer.parseInt(condition.get("limit").toString());
/* 150 */     Object queryObj = condition.get("query");
/*     */ 
/* 152 */     ResultSet rs = null;
/* 153 */     List fileList = new ArrayList();
/*     */     try {
/* 155 */       String strSQL = "select count(id) from dictionary";
/* 156 */       if ((queryObj != null) && (!"".equals(queryObj.toString().trim())))
/* 157 */         strSQL = "select count(id) from dictionary where dictype = '" + queryObj.toString().trim() + "'";
/* 158 */       log.info(strSQL);
/* 159 */       rs = this.dbcon.execQuery(strSQL);
/* 160 */       if (rs.next()) {
/* 161 */         bfo.setTotalSize(rs.getInt(1));
/*     */       }
/* 163 */       strSQL = "select * from dictionary order by id desc limit " + start + ", " + limit;
/* 164 */       if ((queryObj != null) && (!"".equals(queryObj.toString().trim()))) {
/* 165 */         strSQL = "select * from dictionary where dictype = '" + queryObj.toString().trim() + "' order by dictype,id limit " + start + ", " + limit;
/*     */       }
/* 167 */       log.info(strSQL);
/* 168 */       rs = this.dbcon.execQuery(strSQL);
/* 169 */       while (rs.next()) {
/* 170 */         DictionaryBO bo = new DictionaryBO();
/* 171 */         bo.setId(rs.getString("id"));
/* 172 */         bo.setDictype(rs.getString("dictype"));
/* 173 */         bo.setDictypename(rs.getString("dictypename"));
/* 174 */         bo.setDiccode(rs.getString("diccode"));
/* 175 */         bo.setDicname(rs.getString("dicname"));
/* 176 */         fileList.add(bo);
/*     */       }
/* 178 */       bfo.setData(fileList.toArray());
/*     */     } catch (Exception e) {
/* 180 */       e.printStackTrace();
/* 181 */       log.error("query dictionary failed .");
/*     */     } finally {
/* 183 */       dbConClose();
/* 184 */       log.info(" query dictionary end .");
/*     */     }
/* 186 */     return bfo;
/*     */   }
/*     */ 
/*     */   public boolean saveDict(DictionaryBO bo)
/*     */   {
/* 191 */     boolean flag = true;
/*     */     try {
/* 193 */       dbConInit();
/* 194 */       String strSQL = "insert into dictionary (dictype,dictypename,diccode,dicname) values ('" + bo.getDictype() + "','" + bo.getDictypename() + "','" + bo.getDiccode() + "','" + bo.getDicname() + "' )  ";
/* 195 */       log.info(strSQL);
/* 196 */       this.dbcon.execUpdate(strSQL);
/*     */     } catch (Exception e) {
/* 198 */       flag = false;
/* 199 */       e.printStackTrace();
/* 200 */       log.error(e.getMessage());
/* 201 */       log.error("save dictionary failure ");
/*     */     } finally {
/* 203 */       dbConClose();
/*     */     }
/* 205 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean updateDict(DictionaryBO bo)
/*     */   {
/* 210 */     boolean flag = true;
/*     */     try {
/* 212 */       dbConInit();
/* 213 */       StringBuffer buf = new StringBuffer();
/* 214 */       buf.append("update dictionary set ");
/* 215 */       buf.append(" dictype = '" + bo.getDictype() + "' ,");
/* 216 */       buf.append(" dictypename = '" + bo.getDictypename() + "' ,");
/* 217 */       buf.append(" diccode = '" + bo.getDiccode() + "' ,");
/* 218 */       buf.append(" dicname = '" + bo.getDicname() + "' ");
/* 219 */       buf.append(" where id = '" + bo.getId() + "' ");
/* 220 */       log.info(buf.toString());
/* 221 */       this.dbcon.execUpdate(buf.toString());
/*     */     } catch (Exception e) {
/* 223 */       flag = false;
/* 224 */       e.printStackTrace();
/* 225 */       log.error(e.getMessage());
/* 226 */       log.error("save dictionary failure ");
/*     */     } finally {
/* 228 */       dbConClose();
/*     */     }
/* 230 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean deleteDic(String strId)
/*     */   {
/* 237 */     boolean flag = true;
/*     */     try {
/* 239 */       dbConInit();
/* 240 */       String strSQL = "delete from dictionary  where id = '" + strId + "' ";
/* 241 */       log.info(strSQL);
/* 242 */       this.dbcon.execUpdate(strSQL);
/*     */     } catch (Exception e) {
/* 244 */       flag = false;
/* 245 */       e.printStackTrace();
/* 246 */       log.error(e.getMessage());
/* 247 */       log.error("delete dictionary failure ");
/*     */     } finally {
/* 249 */       dbConClose();
/*     */     }
/* 251 */     return flag;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.dao.station.CommDAO
 * JD-Core Version:    0.6.2
 */